import { ref } from "vue";
import { http } from "../http";

export function useModel(resource: string | undefined) {
  const model = ref({}) as any;
  const findModel = async (id: string | undefined) => {
    model.value = (await http.get(`/${resource}/${id}`)).data;
  };
  const createModel = async () => {
    await http.post(`/${resource}`, model.value);
  };
  const updateModel = async (id: string | undefined, model: any) => {
    await http.patch(`/${resource}/${id}`, model);
  };

  return {
    model,
    findModel,
    createModel,
    updateModel,
  };
}
